1、添加MvcPager.dll引用
2、页面引用
@using Webdiyer.WebControls.Mvc@model PagedList//指定model类型
3、在<bodey>编辑
@*-----搜索表单-------*@ @* UpdateTargetId 异步更新模块id ListContent *@@using (Ajax.BeginForm("AdminList", new RouteValueDictionary { { "id", "" } }, new AjaxOptions { UpdateTargetId = "ListContent", InsertionMode = InsertionMode.Replace, HttpMethod = "Post" }, new RouteValueDictionary { { "id", "searchForm" } })) {@*-----异步更新模块-------*@ } @*-----搜索表单结束-------*@@Html.Partial("_AjaxAdminList", Model)
@*-----异步更新模块结束-------*@
4、添加分部视图_AjaxAdminList
@using Webdiyer.WebControls.Mvc@model PagedList@Html.Partial("~/Areas/Cms/Views/Shared/PartialPage.cshtml", Model) @*分页显示*@
@if (Model != null && Model.Any()) { string className; foreach (var md in Model) { className = ""; if (Convert.ToInt32(md["ClassID"]) == 3) {className = "数据管理员";} if (Convert.ToInt32(md["ClassID"]) == 4) {className = "系统管理员";} if (Convert.ToInt32(md["ClassID"]) == 5) {className = "超级管理员";} 管理员编号 管理员姓名 管理员级别 添加时间 状态 操作 } } else { @if (Convert.ToInt32(md["id"]) != 1) { } @md["userName"] @md["name"] @className @md["addTime"] @(Convert.ToInt32(md["status"])==0? "正常": "禁用" ) @if (Convert.ToInt32(md["id"]) != 1) { 编辑 @(Convert.ToInt32(md["status"]) == 0 ? "禁用" : "启用") 删除 } } 未有数据
5、在Shared创建PartialPage分部视图
@using Webdiyer.WebControls.Mvc@model PagedList @*之前的分页样式*@@* @**@ @Ajax.Pager(Model, new PagerOptions { PageIndexParameterName = "page", ShowPageIndexBox = false, ShowGoButton = false, AutoHide = false, ContainerTagName = "ul", CssClass = "paginList", CurrentPagerItemWrapperFormatString = "
- {0}
", ShowFirstLast=false, PagerItemWrapperFormatString = "- {0}
", NextPageText = " ", PrevPageText = " " }, new MvcAjaxOptions { UpdateTargetId = "ListContent", HttpMethod = "Post", DataFormId = "searchForm" })1 2 3 4 5 ... 10 *@
6、在控制器中创建AdminList方法
public ActionResult AdminList(int page=1) { int total; StringBuilder strSql = new StringBuilder(); strSql.Append("id>0 "); string startDate = Common.Tool.GetSafeSqlandHtml(Request["addTimeS"]); string overDate = Common.Tool.GetSafeSqlandHtml(Request["addTimeE"]); if (!String.IsNullOrEmpty(startDate.Trim()) && StringHelp.IsDate(startDate)) { if (startDate.Trim().Length <= 10) { strSql.Append(" and addTime>='" + startDate + " 00:00:00'"); } else { strSql.Append(" and addTime>='" + startDate + "'"); } } if (!String.IsNullOrEmpty(overDate.Trim()) && StringHelp.IsDate(overDate)) { if (overDate.Trim().Length <= 10) { strSql.Append(" and addTime<='" + overDate + " 23:59:59'"); } else { strSql.Append(" and addTime<='" + overDate + "'"); } } PagedListpros = null; DataSet dt = BLL.User.GetUserList(page, 10, " addTime desc", strSql.ToString(), out total); pros = new PagedList (dt.Tables[0].Select(), page, 10, total); if (Request.IsAjaxRequest()) return PartialView("_AjaxAdminList", pros); return View(pros); }
了解更多可查看 的
最终效果: